/*
 * $Id: IPTDSProperties.java,v 1.6 2009/07/29 17:21:46 oliver Exp $
 * 
 * Copyright (C) 2008 General Electric Company. All Rights Reserved.
 * 
 * This software is the confidential and proprietary information of the General
 * Electric Company (GE). You shall not disclose this software and shall use it
 * only in accordance with the terms of the license agreement you entered into
 * with GE.
 * 
 * GE MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
 * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
 * NON-INFRINGEMENT. GE SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
 * AS A RESULT OF USING, MODIFYING, OR DISTRIBUTING THIS SOFTWARE OR ITS
 * DERIVATIVES.
 */
package com.ge.healthcare.autosc.processor.iptds;

import com.ge.healthcare.autosc.common.ASCLogger;
import com.ge.healthcare.autosc.common.util.ApplicationInfo;
import com.ge.healthcare.autosc.common.util.PropertyConstants;

/**
 * 
 * @author 212042946 
 * 
 */
//TO DO: It does not have to wire this. Make this as static class.
public class IPTDSProperties {

	public static final int DEFAULT_WORKER_NUM = 25;
	public static final int DEFAULT_SERVER_PORT = 7979;
	public static final int DEFAULT_SERVER_SOCKET_TIMEOUT = 5000;
	public static final int DEFAULT_CLIENT_SOCKET_TIMEOUT = 120000;
	public static final int DEFAULT_URGENT_WORKERS = 1;
	public static final int DEFAULT_SHUTDOWN_GRACE_PERIOD = 10;

	public IPTDSProperties() {
	}

	public int getListenPort() {
		return getProperty(PropertyConstants.IPTDS_SERVER_PORT,
				DEFAULT_SERVER_PORT);
	}

	public int getIPTDSWorkerNum() {
		return getProperty(PropertyConstants.IPTDS_WORKER_NUM,
				DEFAULT_WORKER_NUM);
	}

	public int getServerSocketTimeout() {
		return getProperty(PropertyConstants.IPTDS_SERVER_SOCKET_TIMEOUT,
				DEFAULT_SERVER_SOCKET_TIMEOUT);
	}

	public int getSocketTimeout() {
		return getProperty(PropertyConstants.IPTDS_CLIENT_SOCKET_TIMEOUT,
				DEFAULT_CLIENT_SOCKET_TIMEOUT);
	}

	public int getUrgentWorkers() {
		return getProperty(PropertyConstants.IPTDS_URGENT_WORKERS,
				DEFAULT_URGENT_WORKERS);
	}

	public int getShutdownGracePeriodInSec() {
		return getProperty(
				PropertyConstants.IPTDS_SHUTDOWN_GRACE_PERIOD_IN_SEC,
				DEFAULT_SHUTDOWN_GRACE_PERIOD);
	}

	private int getProperty(String name, int defaultValue) {
		int value;
		try {
			String dValue = Integer.toString(defaultValue);
			value = ApplicationInfo.getInstance().getIntegerPropertyValue(
					name, dValue);
		} catch (NumberFormatException nfe) {
			ASCLogger.error(this.getClass(), "getProperty",
					"Invalid property value, check autosc properties. PropertyName="
							+ name, nfe);
			throw nfe;
		}
		return value;

	}
}
